package com.yx1996.management.ExcelUtils;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.yx1996.management.Bean.User;
import com.yx1996.management.Listener.ExcelListener;
import org.springframework.stereotype.Component;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;

@Component
public class ReadExcel2003 {

    public static List<User> readFile(String filepath) throws FileNotFoundException {
        List<User> users;
        InputStream inputStream = new BufferedInputStream(new FileInputStream(filepath));

        ExcelListener excelListener = new ExcelListener();
        EasyExcelFactory.readBySax(inputStream, new Sheet(1, 1, User.class), excelListener);
        users = excelListener.getdata();
        return users;
    }
}
